package edu.xhu.video.util;

import edu.xhu.model.behavior.vo.CommentTree;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

public class CommentTreeUtil {
    /**
     * 将 map 中的 kv 复制到评论bean相应的属性
     *
     * @param map         保存了评论信息的map
     * @param commentTree 根评论或者子评论
     */
    public static void copyMapToCommentBeanProperties(Map<String, Object> map, CommentTree commentTree) {
        if (map.containsKey("love"))
            commentTree.setLove((Integer) map.get("love"));
        if (map.containsKey("deep"))
            commentTree.setDeep((Integer) map.get("deep"));
        if (map.containsKey("bad"))
            commentTree.setBad((Integer) map.get("bad"));
        if (map.containsKey("create_time"))
            commentTree.setCreateTime(new Date((Long) map.get("create_time")));
        if (map.containsKey("total_comment_size"))
            commentTree.setTotalCommentSize((Integer) map.get("total_comment_size"));
        if (map.containsKey("comment_id"))
            commentTree.setCommentId((Long) map.get("comment_id"));
        if (map.containsKey("content"))
            commentTree.setContent((String) map.get("content"));
        if (map.containsKey("is_top"))
            commentTree.setIsTop((String) map.get("is_top"));
        if (map.containsKey("is_delete"))
            commentTree.setIsDelete((String) map.get("is_delete"));
        if (map.containsKey("score"))
            commentTree.setScore(Double.parseDouble(map.get("score").toString()));
        if (map.containsKey("user_id"))
            commentTree.setUserId((Long) map.get("user_id"));
        if (map.containsKey("is_like"))
            commentTree.setIsLike((String) map.get("is_like"));
        if (map.containsKey("parent_id"))
            commentTree.setParentId(Long.parseLong(map.get("parent_id").toString()));
        if (map.containsKey("to_user_id"))
            commentTree.setToUserId(Long.parseLong(map.get("to_user_id").toString()));
        if (map.containsKey("root_id"))
            commentTree.setRootId(Long.parseLong(map.get("root_id").toString()));
        if (map.containsKey("video_id"))
            commentTree.setVideoId((Long) map.get("video_id"));
    }
}
